<?php
namespace App;

use Medoo\Medoo;

require_once '../vendor/autoload.php';


class MedooDB
{
    private static $_instance;    //保存实例在此属性中

    protected $options = [
        'database_type' => 'mysql',
        'database_name' => 'youtube',
        'server' => '127.0.0.1',
        'username' => 'root',
        'password' => 'wewrjjdsl@oo888rmds'
    ];

    //构造函数声明为private,防止直接创建对象
    private function __construct($options){

        if (!empty($options)) {
            $this->options = array_merge($this->options, $options);
        }

        self::$_instance = new Medoo($this->options);

    }

    //单例方法
    public static function getInstance(array $config=[]):MedooDB
    {
        if (!isset(self::$_instance) or FALSE == (self::$_instance instanceof self)) {
            self::$_instance = new self($config);
        }
        return self::$_instance;
    }

    //阻止用户复制对象实例
    private function __clone(){
        trigger_error('Clone is not allow',E_USER_ERROR);
    }

}




